unit TemeljnicaFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBBaseFrm, DokumentDetajlFrm, cxStyles, cxCustomData, cxGraphics, cxFilter,
  cxData, cxEdit, DB, cxDBData, cxDBEditRepository, cxEditRepositoryItems,
  cxContainer, DBClient, MConnect, alBaseDataSet, StdActns, ActnList,
  cxDropDownEdit, cxCalendar, cxDBEdit, cxTextEdit, cxMaskEdit,
  cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, StdCtrls, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, ExtCtrls, cxGridBandedTableView,
  cxGridDBBandedTableView, Mask, ImgList, DokumentStatus, PoslovanjeSrv_TLB,
  cxDataStorage, cxExtEditRepositoryItems, cxCheckComboBox,
  cxDBCheckComboBox, alActions, kdbinfo, kdbstruc, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TcxLookupComboBoxCrack = class(TcxLookupComboBox);

  TfrmTemeljnica = class(TfrmDokumentDetajl)
    lblSkupina: TLabel;
    lkpcbSkupina: TcxDBLookupComboBox;
    scnSkupina: TSharedConnection;
    cdsSkupina: TBaseDataSet;
    dtsrcSkupina: TDataSource;
    dtsrcKonto: TDataSource;
    scnKonto: TSharedConnection;
    cdsKonto: TBaseDataSet;
    rpstMainPostavkaOpomba: TcxEditRepositoryTextItem;
    rpstMainPostavkaKontoSifra: TcxEditRepositoryLookupComboBoxItem;
    rpstMainPostavkaVrednost: TcxEditRepositoryCurrencyItem;
    grdtvPostavkaOpomba: TcxGridDBBandedColumn;
    grdtvPostavkaKontoSifra: TcxGridDBBandedColumn;
    grdtvPostavkaKredit: TcxGridDBBandedColumn;
    grdtvPostavkaDebet: TcxGridDBBandedColumn;
    grdtvPostavkaSifrantNazivEdit: TcxGridDBBandedColumn;
    scnSifrant: TSharedConnection;
    cdsSifrant: TBaseDataSet;
    dtsrcSifrant: TDataSource;
    rpstMainSkupinaNaziv: TcxEditRepositoryLookupComboBoxItem;
    grdtvPostavkaKontoNaziv: TcxGridDBBandedColumn;
    grdtvMainDetajlSifrant: TcxGridDBTableView;
    grdtvMainDetajlSifrantSifrantSifra: TcxGridDBColumn;
    grdtvMainDetajlSifrantSifrantNaziv: TcxGridDBColumn;
    grdtvMainDetajlSifrantSifrantID: TcxGridDBColumn;
    grdtvMainDetajlSifrantSifrantClassNaziv: TcxGridDBColumn;
    rpstMainPostavkaSifrantNazivEdit: TcxEditRepositoryLookupComboBoxItem;
    rpstMainPostavkaKontoNaziv: TcxEditRepositoryLookupComboBoxItem;
    grdtvMainSkupinaOznaka: TcxGridDBBandedColumn;
    rpstMainSkupinaOznakaEdit: TcxEditRepositoryLookupComboBoxItem;
    grdtvPostavkaStevilkaEdit: TcxGridDBBandedColumn;
    rpstMainPostavkaStevilkaEdit: TcxEditRepositoryLookupComboBoxItem;
    rpstMainPostavkaStevilka: TcxEditRepositoryTextItem;
    cdsKontoSaldo: TBaseDataSet;
    scnKontoSaldo: TSharedConnection;
    dtsrcKontoSaldo: TDataSource;
    rpstMainSkupinaOznaka: TcxEditRepositoryTextItem;
    grdtvPostavkaStevilka: TcxGridDBBandedColumn;
    rpstMainPostavkaKontoRazredID: TcxEditRepositoryTextItem;
    grdtvPostavkaKontoRazredID: TcxGridDBBandedColumn;
    grdtvMainSaldo: TcxGridDBBandedColumn;
    cdsSifrantEdit: TBaseDataSet;
    dtsrcSifrantEdit: TDataSource;
    rpstMainPostavkaSifrantNaziv: TcxEditRepositoryLookupComboBoxItem;
    grdtvPostavkaStevilkaSkupine: TcxGridDBBandedColumn;
    rpstMainPostavkaStevilkaSkupine: TcxEditRepositoryMaskItem;
    actnPrenosGlavnaKnjiga: TAction;
    actnPrenosKnjigaIzdanihRacunov: TAction;
    actnPrenosKnjigaPrejetihRacunov: TAction;
    cxstyContentTransferedGK: TcxStyle;
    cxstyContentTransferedKIR: TcxStyle;
    cxstyContentTransferedKPR: TcxStyle;
    actnStornoPrenosGlavnaKnjiga: TAction;
    actnStornoPrenosKnjigaIzdanihRacunov: TAction;
    actnStornoPrenosKnjigaPrejetihRacunov: TAction;
    actnTemeljnica: TReportPrint;
    procedure actnOpravilaExecute(Sender: TObject);
    procedure OnCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure OnCustomDrawPartBackground(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
    procedure OnCustomDrawFooterCell(
      Sender: TcxGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
    procedure OnGetProperties(
      Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
      var AProperties: TcxCustomEditProperties);
    procedure OnGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure OnSummary(
      ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
      var OutArguments: TcxSummaryEventOutArguments);
    procedure OnGetDisplayText(
      Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
      var AText: String);
    procedure OnEditValueChanged(Sender: TObject);
    procedure OnInitPopup(Sender: TObject);
    procedure OnFocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure OnGetPropertiesForEdit(Sender: TcxCustomGridTableItem;
      ARecord: TcxCustomGridRecord; var AProperties: TcxCustomEditProperties);
  private

  protected
    function GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations; override;
    procedure Deinitialize; override;
    procedure DoDBRefresh; override;
    procedure DoRefreshLookup(ADataSet: TBaseDataSet; ARecord: TcxCustomGridRecord;
      AHardRefresh: Boolean = False);
    procedure Initialize; override;
    procedure Loaded; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  frmTemeljnica: TfrmTemeljnica;

implementation

uses
  MainFrm, IzbiraZapisaFrm;

{$R *.dfm}

{ TfrmTemeljnica }

procedure TfrmTemeljnica.actnOpravilaExecute(Sender: TObject);
var
  AStevilkaDokumenta: Variant;
  AStevilkeDokumentov: Variant;
  ARecord: TcxCustomGridRecord;
  AIzbiraZapisaFrm: TfrmIzbiraZapisa;
begin
  inherited;
  if (Sender = actnPrenosGlavnaKnjiga) or (Sender = actnStornoPrenosGlavnaKnjiga) or
    (Sender = actnPrenosKnjigaIzdanihRacunov) or (Sender = actnStornoPrenosKnjigaIzdanihRacunov) or
    (Sender = actnPrenosKnjigaPrejetihRacunov) or (Sender = actnStornoPrenosKnjigaPrejetihRacunov) then
  begin
    ARecord := grdtvMain.Controller.FocusedRecord;
    if Assigned(ARecord) then
    begin
      AStevilkaDokumenta := VarToStrDef(ARecord.Values[grdtvMainStevilka.Index], '-1');
      AIzbiraZapisaFrm := TfrmIzbiraZapisa.Create(nil);
      try
        AIzbiraZapisaFrm.edtOdStevilke.Text := AStevilkaDokumenta;
        AIzbiraZapisaFrm.edtDoStevilke.Text := AStevilkaDokumenta;
        AIzbiraZapisaFrm.ShowModal;
        if AIzbiraZapisaFrm.ModalResult = mrOK then
        begin
          case AIzbiraZapisaFrm.Izbira of
            1: AStevilkeDokumentov := VarArrayOf([AIzbiraZapisaFrm.edtOdStevilke.Value]);
            2: AStevilkeDokumentov := VarArrayOf([AIzbiraZapisaFrm.edtOdStevilke.Value, AIzbiraZapisaFrm.edtDoStevilke.Value]);
          end;
          if (Sender = actnPrenosGlavnaKnjiga) then
            (cdsMain.AppServer as IrdmTemeljnica).PrenosGlavnaKnjiga(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov)
          else if (Sender = actnStornoPrenosGlavnaKnjiga) then
            (cdsMain.AppServer as IrdmTemeljnica).StornoPrenosGlavnaKnjiga(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov)
          else if (Sender = actnPrenosKnjigaIzdanihRacunov) then
            (cdsMain.AppServer as IrdmTemeljnica).PrenosKnjigaIzdanihRacunov(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov)
          else if (Sender = actnStornoPrenosKnjigaIzdanihRacunov) then
            (cdsMain.AppServer as IrdmTemeljnica).StornoPrenosKnjigaIzdanihRacunov(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov)
          else if (Sender = actnPrenosKnjigaPrejetihRacunov) then
            (cdsMain.AppServer as IrdmTemeljnica).PrenosKnjigaPrejetihRacunov(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov)
          else if (Sender = actnStornoPrenosKnjigaPrejetihRacunov) then
            (cdsMain.AppServer as IrdmTemeljnica).StornoPrenosKnjigaPrejetihRacunov(Session, AIzbiraZapisaFrm.Izbira, AStevilkeDokumentov);
          case AIzbiraZapisaFrm.Izbira of
            1: cdsMain.RefreshRecord;
            2: cdsMain.Refresh(False);
          end;
        end;
      finally
        AIzbiraZapisaFrm.Free;
      end;
    end;
  end;
end;

constructor TfrmTemeljnica.Create(AOwner: TComponent);
begin
  inherited;
  with grdtvMainDetajlSifrant do
  begin
    OptionsData.Deleting := False;
    OptionsData.Editing := False;
    OptionsData.Inserting := False;
    OptionsSelection.CellSelect := False;
    OptionsView.ColumnAutoWidth := True;
    OptionsView.GroupByBox := False;
  end;
end;

procedure TfrmTemeljnica.Deinitialize;
begin
  cdsKonto.Close;
  cdsSkupina.Close;
  cdsSifrant.Close;
  inherited;
end;

procedure TfrmTemeljnica.DoDBRefresh;
begin
  inherited;
  cdsSifrant.Refresh;
  cdsSkupina.Refresh;
  cdsKonto.Refresh;
end;

procedure TfrmTemeljnica.DoRefreshLookup(ADataSet: TBaseDataSet;
  ARecord: TcxCustomGridRecord; AHardRefresh: Boolean);
var
  ADatum: Variant;
  AKontoID: Variant;
  ASifrantID: Variant;
  ARazredID: Variant;
  APodrazredList: string;
  APostavkaID: Variant;
begin
  if Assigned(ARecord) then
  begin
    if (ADataSet = cdsSifrantEdit) then
    begin
      if cdsKonto.Active then
      begin
        AKontoID := VarToStrDef(ARecord.Values[grdtvPostavkaKontoSifra.Index], '-1');
        ARazredID := VarToStrDef(cdsKonto.Lookup('ID', AKontoID, 'RAZRED_ID'), '-1');
      end
      else
        ARazredID := VarToStrDef(ARecord.Values[grdtvPostavkaKontoRazredID.Index],'-1' );
      APodrazredList := MainServer.PodrazredList[ARazredID];
      ADataSet.Filter := Format('RAZRED__ID IN (%s)', [APodrazredList]);
    end
    else if (ADataSet = cdsKontoSaldo) then
    begin
      APostavkaID := VarToStrDef(ARecord.Values[grdtvPostavkaID.Index], '-1');
      AKontoID := VarToStrDef(ARecord.Values[grdtvPostavkaKontoSifra.Index], '-1');
      ASifrantID := VarToStrDef(ARecord.Values[grdtvPostavkaSifrantNazivEdit.Index], '-1');
      ADatum := cdsMain.FieldByName('DATUM').AsDateTime;
      with ADataSet.Params do
      begin
        if (ParamByName('POSTAVKA_POSTAVKA_ID').Value <> APostavkaID) or
          (ParamByName('POSTAVKA_KONTO_ID').Value <> AKontoID) or
          (ParamByName('POSTAVKA_SIFRANT_ID').Value <> ASifrantID) or
          (ParamByName('DATUM').Value <> ADatum) or
          AHardRefresh then
        begin
          ADataSet.Close;
          ParamByName('POSTAVKA_POSTAVKA_ID').Value := APostavkaID;
          ParamByName('POSTAVKA_KONTO_ID').Value := AKontoID;
          ParamByName('POSTAVKA_SIFRANT_ID').Value := ASifrantID;
          ParamByName('DATUM').Value := ADatum;
          ADataSet.Open;
        end;
      end;
    end;
  end;
end;

function TfrmTemeljnica.GetSessionParamRelations(DataSet: TDataSet): TSessionParamRelations;
begin
  Result := inherited GetSessionParamRelations(DataSet);
  if DataSet = cdsKonto then
  begin
    SetLength(Result, 1);
    Result[0].FieldName := 'REF_ID';
    Result[0].SessionName := 'POSLOVNO_LETO_ID';
  end;
end;

procedure TfrmTemeljnica.Initialize;
begin
  inherited;
  cdsSifrant.Open;
  cdsSifrantEdit.CloneCursor(cdsSifrant, False);
  cdsSifrantEdit.Filtered := True;
  cdsSkupina.Open;
  cdsKonto.Open;
  grdtvPostavka.ViewData.Expand(False);
end;

procedure TfrmTemeljnica.Loaded;
begin
  inherited;
  grdtvMainSkupinaOznaka.Visible := False;
  grdtvMainSaldo.Visible := False;
  grdtvPostavkaStevilka.Visible := False;
  grdtvPostavkaKontoRazredID.Visible := False;
  grdtvPostavkaKontoNaziv.Position.RowIndex := 1;
end;

procedure TfrmTemeljnica.OnCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  inherited;
  if Sender = grdtvMain then
  begin
    ADone := False;
  end;
end;

procedure TfrmTemeljnica.OnCustomDrawPartBackground(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean);
var
  ASaldo: Variant;
begin
  if Sender = grdtvPostavka then
  begin
    with AViewInfo do
    begin
      case GetHitTest(Bounds.TopLeft).HitTestCode of
        htFooter:
          begin
            ASaldo := VarToStrDef(Sender.DataController.Summary.FooterSummaryValues[0], '0');
            if not VarIsNull(ASaldo) then
            begin
              with ACanvas do
              begin
                FillRect(ContentBounds);
                if Abs(ASaldo) > Eps then
                  Font.Color := clRed
                else
                  Font.Color := clGreen;
                Font.Style := [fsBold];
                DrawText(' SALDO = ' + FormatFloat('#,##0.00', ASaldo), AViewInfo.ContentBounds, cxAlignVCenter);
                ADone := True;
              end;
            end;
          end;
        else
          ADone := False;
      end;
    end;
  end;
end;

procedure TfrmTemeljnica.OnCustomDrawFooterCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
begin
  inherited;
  if (Sender = grdtvPostavka) then
  begin
    if AViewInfo.Column = grdtvPostavkaOpomba then
    begin
      ADone := True;
    end;
  end;
end;

procedure TfrmTemeljnica.OnEditValueChanged(
  Sender: TObject);
var
  AValue: Variant;
begin
  inherited;
  if Sender is TcxLookupComboBox then
  begin
    with Sender as TcxLookupComboBox do
    begin
      TcxLookupComboBoxCrack(Sender).PostEditValue;
      if Properties.ListSource = dtsrcKontoSaldo then
      begin
        if (not VarIsEmpty(EditValue)) and cdsKontoSaldo.Active then
        begin
          AValue := cdsKontoSaldo.Lookup('POSTAVKA_POSTAVKA_ID', EditValue, 'SALDO');
          if VarIsNull(AValue) then
            AValue := 0;
          if AValue < 0 then
          begin
            grdtvPostavkaDebet.EditValue := Abs(AValue);
            grdtvPostavkaKredit.EditValue := 0;
          end
          else begin
            grdtvPostavkaDebet.EditValue := 0;
            grdtvPostavkaKredit.EditValue := Abs(AValue);
          end;
        end;
      end
      else if (Properties.ListSource = dtsrcKonto) then
      begin
        grdtvPostavkaSifrantNazivEdit.EditValue := Null;
        grdtvPostavkaStevilkaEdit.EditValue := Null;
      end
      else if (Properties.ListSource = dtsrcSifrantEdit) then
      begin
        grdtvPostavkaStevilkaEdit.EditValue := Null;
      end;
    end;
  end;
end;

procedure TfrmTemeljnica.OnFocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
var
  AStatus: Variant;
  ASkupinaOznaka: Variant;
begin
  inherited;
  if Sender = grdtvMain then
  begin
    cdsMain.AllowedOperations := [opInsert];
    cdsPostavka.AllowedOperations := [];
    actnPrenosGlavnaKnjiga.Enabled := False;
    actnPrenosKnjigaIzdanihRacunov.Enabled := False;
    actnPrenosKnjigaPrejetihRacunov.Enabled := False;
    actnStornoPrenosGlavnaKnjiga.Enabled := False;
    actnStornoPrenosKnjigaIzdanihRacunov.Enabled := False;
    actnStornoPrenosKnjigaPrejetihRacunov.Enabled := False;
    if Assigned(AFocusedRecord) then
    begin
      ASkupinaOznaka := cdsMain.FieldByName('SKUPINA_OZNAKA').AsString;
      AStatus := cdsMain.FieldByName('STATUS').AsString;
      //ASkupinaOznaka := VarToStrDef(AFocusedRecord.Values[grdtvMainSkupinaOznaka.Index], '-1');
      //AStatus := VarToStrDef(AFocusedRecord.Values[grdtvMainStatus.Index], '0');
      if not GetBit(stTemeljnicaPrenosGKBit, AStatus) then
      begin
        cdsMain.AllowedOperations := [opInsert, opDelete, opEdit];
        cdsPostavka.AllowedOperations := [opInsert, opDelete, opEdit];
      end;
      if not GetBit(stTemeljnicaPrenosGKBit, AStatus) then
        actnPrenosGlavnaKnjiga.Enabled := True
      else
        actnStornoPrenosGlavnaKnjiga.Enabled := True;
      if (ASkupinaOznaka = 'IR') then
      begin
        if not GetBit(stTemeljnicaPrenosKIRBit, AStatus) then
          actnPrenosKnjigaIzdanihRacunov.Enabled := True
        else
          actnStornoPrenosKnjigaIzdanihRacunov.Enabled := True;
      end;
      if (ASkupinaOznaka = 'PR') then
      begin
        if not GetBit(stTemeljnicaPrenosKPRBit, AStatus) then
          actnPrenosKnjigaPrejetihRacunov.Enabled := True
        else
          actnStornoPrenosKnjigaPrejetihRacunov.Enabled := True;
      end;
    end;
  end;
end;

procedure TfrmTemeljnica.OnGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
var
  ASaldo: Variant;
  AStatus: Variant;
begin
  inherited; //
  if Sender = grdtvMain then
  begin
    if Assigned(ARecord) then
    begin
      if AItem = grdtvMainStevilka then
      begin
        ASaldo := VarToStrDef(ARecord.Values[grdtvMainSaldo.Index], '-1');
        if Abs(ASaldo) > Eps then
          AStyle := cxstyContentWarning;
        AStatus := VarToStrDef(ARecord.Values[grdtvMainStatus.Index], '0');
        if GetBit(stTemeljnicaPrenosGKBit, AStatus) then
          AStyle := cxstyContentTransferedGK;
        if GetBit(stTemeljnicaPrenosKIRBit, AStatus) then
          AStyle := cxstyContentTransferedKIR;
        if GetBit(stTemeljnicaPrenosKPRBit, AStatus) then
          AStyle := cxstyContentTransferedKPR;
      end;
    end;
  end;
end;

procedure TfrmTemeljnica.OnGetDisplayText(Sender: TcxCustomGridTableItem;
  ARecord: TcxCustomGridRecord; var AText: String);
var
  AID: Variant;
  APostavkaID: Variant;
begin
  inherited;
  if ARecord.HasCells then
  begin
    if Sender = grdtvMainStevilka then
    begin
      AText := Format('%0:s %1:s',
        [VarToStrDef(ARecord.Values[grdtvMainSkupinaOznaka.Index], '-'), AText]);
    end
    else if Sender = grdtvPostavkaStevilkaEdit then
    begin
      AID := VarToStrDef(ARecord.Values[grdtvPostavkaID.Index], '-1');
      APostavkaID := VarToStrDef(ARecord.Values[grdtvPostavkaStevilkaEdit.Index], '-1');
      if (APostavkaID = -1) or (AID = APostavkaID) then
        AText := ''
      else
        AText := VarToStrDef(ARecord.Values[grdtvPostavkaStevilka.Index], '-1');
    end;
  end;
end;

procedure TfrmTemeljnica.OnGetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
begin
  inherited;
  {if Assigned(ARecord) and ARecord.Focused then
  begin
    if Sender = grdtvPostavkaSifrantNazivEdit then
    begin
      DoRefreshLookup(cdsSifrantEdit, ARecord);
      AProperties := rpstMainPostavkaSifrantNazivEdit.Properties;
    end
    else if Sender = grdtvPostavkaStevilkaEdit then
    begin
      DoRefreshLookup(cdsKontoSaldo, ARecord);
      AProperties := rpstMainPostavkaStevilkaEdit.Properties;
    end;
  end;}
end;

procedure TfrmTemeljnica.OnGetPropertiesForEdit(Sender: TcxCustomGridTableItem;
  ARecord: TcxCustomGridRecord; var AProperties: TcxCustomEditProperties);
begin
  inherited;
  if Assigned(ARecord) and ARecord.Focused then
    begin
    if Sender = grdtvPostavkaSifrantNazivEdit then
    begin
      DoRefreshLookup(cdsSifrantEdit, ARecord);
      AProperties := rpstMainPostavkaSifrantNazivEdit.Properties;
    end
    else if Sender = grdtvPostavkaStevilkaEdit then
    begin
      DoRefreshLookup(cdsKontoSaldo, ARecord);
      AProperties := rpstMainPostavkaStevilkaEdit.Properties;
    end;
  end;
end;

procedure TfrmTemeljnica.OnInitPopup(Sender: TObject);
begin
  inherited;
  {if Sender is TcxLookupComboBox then
  begin
    with Sender as TcxLookupComboBox do
    begin
      if Properties.ListSource = dtsrcKontoSaldo then
      begin
        DoRefreshLookup(cdsKontoSaldo, grdtvPostavka.Controller.FocusedRecord, True);
      end;
    end;
  end;}
end;

procedure TfrmTemeljnica.OnSummary(
  ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
  var OutArguments: TcxSummaryEventOutArguments);
var
  ADebet: Double;
  AKredit: Double;
begin
  inherited;
  if Arguments.SummaryItem.ItemLink = grdtvPostavkaOpomba then
  begin
    ADebet := ASender.DataController.Values[Arguments.RecordIndex, grdtvPostavkaDebet.Index];
    AKredit := ASender.DataController.Values[Arguments.RecordIndex, grdtvPostavkaKredit.Index];
    OutArguments.Value := ADebet - AKredit;
  end;
end;

end.
